<?php
class mset_menu extends CI_Model{
	var $set_menu = "set_menu";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_menu,$nama_menu,$urut_menu,$enable_menu,$master_menu,$jenis_menu,$group_menu,$induk_menu)
	{
		$this->id_menu= $id_menu;
		$this->nama_menu= $nama_menu;
		$this->urut_menu= $urut_menu;
		$this->enable_menu= $enable_menu;
		$this->master_menu= $master_menu;
		$this->jenis_menu= $jenis_menu;
		$this->group_menu= $group_menu;
		$this->induk_menu= $induk_menu;
	}
	
	function getList(){
		$query = $this->db->get($this->set_menu);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getMasterList(){
		$this->db->where('master_menu',"1"); 
		$this->db->where('enable_menu',"1"); 
		$query = $this->db->get($this->set_menu);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getListGalery(){
		$this->db->where('jenis_menu',"2"); 
		$this->db->where('enable_menu',"1"); 
		$query = $this->db->get($this->set_menu);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}

	function navList(){
		$this->db->where('master_menu',"1");
		$this->db->where('enable_menu',"1"); 
		$this->db->order_by("urut_menu", "asc");
		$query = $this->db->get($this->set_menu);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function subNavList(){
		$this->db->select('s.*,m.nama_menu as nama');
		$this->db->from('set_menu s');
		$this->db->join('set_menu m', 'm.id_menu = s.induk_menu', 'left');
		$this->db->where('s.master_menu',"0");
		$this->db->where('s.enable_menu',"1");
		$this->db->where('s.group_menu',"1"); 		
		$this->db->order_by("s.urut_menu", "asc");
		$query = $this->db->get();
		//print_r($query);exit;
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function create()
	{		
		$arrayData = array(
			'id_menu'=>$this->id_menu,
			'nama_menu'=>$this->nama_menu,
			'urut_menu'=>$this->urut_menu,
			'enable_menu'=>$this->enable_menu,
			'master_menu'=>$this->master_menu,
			'jenis_menu'=>$this->jenis_menu,
			'group_menu'=>$this->group_menu,
			'induk_menu'=>$this->induk_menu
		);
		return $this->db->insert($this->set_menu, $arrayData);
	}
	
	function update($id_menu)
	{
		$arrayData = array(
			'nama_menu'=>$this->nama_menu,
			'urut_menu'=>$this->urut_menu,
			'enable_menu'=>$this->enable_menu,
			'master_menu'=>$this->master_menu,
			'jenis_menu'=>$this->jenis_menu,
			'group_menu'=>$this->group_menu,
			'induk_menu'=>$this->induk_menu
		);
		$this->db->where('id_menu', $id_menu);
		return $this->db->update($this->set_menu, $arrayData);
	}
        
	function remove($id_menu)
	{
		$this->db->where('id_menu', $id_menu);
		return $this->db->delete($this->set_menu);
	}	
	
	function detail($id_menu)
	{
		$this->db->where('id_menu', $id_menu);
		$query = $this->db->get($this->set_menu);	
		return $query->result_array();
	}
}
?>